using System;
using System.Collections;

namespace Goheer
{
	namespace EXIF
	{
		/// <summary>
		/// Summary description for translation.
		/// </summary>
		public class translation : Hashtable
		{
			/// <summary>
			/// 
			/// </summary>
			public translation()
			{
				this.Add(0x8769,"Exif IFD");
				this.Add(0x8825,"Gps IFD");
				this.Add(0xFE,"New Subfile Type");
				this.Add(0xFF,"Subfile Type");
				this.Add(0x100,"Image Width");
				this.Add(0x101,"Image Height");
				this.Add(0x102,"Bits Per Sample");
				this.Add(0x103,"Compression");
				this.Add(0x106,"Photometric Interp");
				this.Add(0x107,"Thresh Holding");
				this.Add(0x108,"Cell Width");
				this.Add(0x109,"Cell Height");
				this.Add(0x10A,"Fill Order");
				this.Add(0x10D,"Document Name");
				this.Add(0x10E,"Image Description");
				this.Add(0x10F,"Equip Make");
				this.Add(0x110,"Equip Model");
				this.Add(0x111,"Strip Offsets");
				this.Add(0x112,"Orientation");
				this.Add(0x115,"Samples PerPixel");
				this.Add(0x116,"Rows Per Strip");
				this.Add(0x117,"Strip Bytes Count");
				this.Add(0x118,"Min Sample Value");
				this.Add(0x119,"Max Sample Value");
				this.Add(0x11A,"X Resolution");
				this.Add(0x11B,"Y Resolution");
				this.Add(0x11C,"Planar Config");
				this.Add(0x11D,"Page Name");
				this.Add(0x11E,"X Position");
				this.Add(0x11F,"Y Position");
				this.Add(0x120,"Free Offset");
				this.Add(0x121,"Free Byte Counts");
				this.Add(0x122,"Gray Response Unit");
				this.Add(0x123,"Gray Response Curve");
				this.Add(0x124,"T4 Option");
				this.Add(0x125,"T6 Option");
				this.Add(0x128,"Resolution Unit");
				this.Add(0x129,"Page Number");
				this.Add(0x12D,"Transfer Funcition");
				this.Add(0x131,"Software Used");
				this.Add(0x132,"Date Time");
				this.Add(0x13B,"Artist");
				this.Add(0x13C,"Host Computer");
				this.Add(0x13D,"Predictor");
				this.Add(0x13E,"White Point");
				this.Add(0x13F,"Primary Chromaticities");
				this.Add(0x140,"ColorMap");
				this.Add(0x141,"Halftone Hints");
				this.Add(0x142,"Tile Width");
				this.Add(0x143,"Tile Length");
				this.Add(0x144,"Tile Offset");
				this.Add(0x145,"Tile ByteCounts");
				this.Add(0x14C,"InkSet");
				this.Add(0x14D,"Ink Names");
				this.Add(0x14E,"Number Of Inks");
				this.Add(0x150,"Dot Range");
				this.Add(0x151,"Target Printer");
				this.Add(0x152,"Extra Samples");
				this.Add(0x153,"Sample Format");
				this.Add(0x154,"S Min Sample Value");
				this.Add(0x155,"S Max Sample Value");
				this.Add(0x156,"Transfer Range");
				this.Add(0x200,"JPEG Proc");
				this.Add(0x201,"JPEG InterFormat");
				this.Add(0x202,"JPEG InterLength");
				this.Add(0x203,"JPEG RestartInterval");
				this.Add(0x205,"JPEG LosslessPredictors");
				this.Add(0x206,"JPEG PointTransforms");
				this.Add(0x207,"JPEG QTables");
				this.Add(0x208,"JPEG DCTables");
				this.Add(0x209,"JPEG ACTables");
				this.Add(0x211,"YCbCr Coefficients");
				this.Add(0x212,"YCbCr Subsampling");
				this.Add(0x213,"YCbCr Positioning");
				this.Add(0x214,"REF Black White");
				this.Add(0x8773,"ICC Profile");
				this.Add(0x301,"Gamma");
				this.Add(0x302,"ICC Profile Descriptor");
				this.Add(0x303,"SRGB RenderingIntent");
				this.Add(0x320,"Image Title");
				this.Add(0x8298,"Copyright");
				this.Add(0x5001,"Resolution X Unit");
				this.Add(0x5002,"Resolution Y Unit");
				this.Add(0x5003,"Resolution X LengthUnit");
				this.Add(0x5004,"Resolution Y LengthUnit");
				this.Add(0x5005,"Print Flags");
				this.Add(0x5006,"Print Flags Version");
				this.Add(0x5007,"Print Flags Crop");
				this.Add(0x5008,"Print Flags Bleed Width");
				this.Add(0x5009,"Print Flags Bleed Width Scale");
				this.Add(0x500A,"Halftone LPI");
				this.Add(0x500B,"Halftone LPIUnit");
				this.Add(0x500C,"Halftone Degree");
				this.Add(0x500D,"Halftone Shape");
				this.Add(0x500E,"Halftone Misc");
				this.Add(0x500F,"Halftone Screen");
				this.Add(0x5010,"JPEG Quality");
				this.Add(0x5011,"Grid Size");
				this.Add(0x5012,"Thumbnail Format");
				this.Add(0x5013,"Thumbnail Width");
				this.Add(0x5014,"Thumbnail Height");
				this.Add(0x5015,"Thumbnail ColorDepth");
				this.Add(0x5016,"Thumbnail Planes");
				this.Add(0x5017,"Thumbnail RawBytes");
				this.Add(0x5018,"Thumbnail Size");
				this.Add(0x5019,"Thumbnail CompressedSize");
				this.Add(0x501A,"Color Transfer Function");
				this.Add(0x501B,"Thumbnail Data");
				this.Add(0x5020,"Thumbnail ImageWidth");
				this.Add(0x502,"Thumbnail ImageHeight");
				this.Add(0x5022,"Thumbnail BitsPerSample");
				this.Add(0x5023,"Thumbnail Compression");
				this.Add(0x5024,"Thumbnail PhotometricInterp");
				this.Add(0x5025,"Thumbnail ImageDescription");
				this.Add(0x5026,"Thumbnail EquipMake");
				this.Add(0x5027,"Thumbnail EquipModel");
				this.Add(0x5028,"Thumbnail StripOffsets");
				this.Add(0x5029,"Thumbnail Orientation");
				this.Add(0x502A,"Thumbnail SamplesPerPixel");
				this.Add(0x502B,"Thumbnail RowsPerStrip");
				this.Add(0x502C,"Thumbnail StripBytesCount");
				this.Add(0x502D,"Thumbnail ResolutionX");
				this.Add(0x502E,"Thumbnail ResolutionY");
				this.Add(0x502F,"Thumbnail PlanarConfig");
				this.Add(0x5030,"Thumbnail ResolutionUnit");
				this.Add(0x5031,"Thumbnail TransferFunction");
				this.Add(0x5032,"Thumbnail SoftwareUsed");
				this.Add(0x5033,"Thumbnail DateTime");
				this.Add(0x5034,"Thumbnail Artist");
				this.Add(0x5035,"Thumbnail WhitePoint");
				this.Add(0x5036,"Thumbnail PrimaryChromaticities");
				this.Add(0x5037,"Thumbnail YCbCrCoefficients");
				this.Add(0x5038,"Thumbnail YCbCrSubsampling");
				this.Add(0x5039,"Thumbnail YCbCrPositioning");
				this.Add(0x503A,"Thumbnail RefBlackWhite");
				this.Add(0x503B,"Thumbnail CopyRight");
				this.Add(0x5090,"Luminance Table");
				this.Add(0x5091,"Chrominance Table");
				this.Add(0x5100,"Frame Delay");
				this.Add(0x5101,"Loop Count");
				this.Add(0x5110,"Pixel Unit");
				this.Add(0x5111,"Pixel PerUnit X");
				this.Add(0x5112,"Pixel PerUnit Y");
				this.Add(0x5113,"Palette Histogram");
				this.Add(0x829A,"Exposure Time");
				this.Add(0x829D,"F-Number");
				this.Add(0x8822,"Exposure Prog");
				this.Add(0x8824,"Spectral Sense");
				this.Add(0x8827,"ISO Speed");
				this.Add(0x8828,"OECF");
				this.Add(0x9000,"Ver");
				this.Add(0x9003,"DTOrig");
				this.Add(0x9004,"DTDigitized");
				this.Add(0x9101,"CompConfig");
				this.Add(0x9102,"CompBPP");
				this.Add(0x9201,"Shutter Speed");
				this.Add(0x9202,"Aperture");
				this.Add(0x9203,"Brightness");
				this.Add(0x9204,"Exposure Bias");
				this.Add(0x9205,"MaxAperture");
				this.Add(0x9206,"SubjectDist");
				this.Add(0x9207,"Metering Mode");
				this.Add(0x9208,"LightSource");
				this.Add(0x9209,"Flash");
				this.Add(0x920A,"FocalLength");
				this.Add(0x927C,"Maker Note");
				this.Add(0x9286,"User Comment");
				this.Add(0x9290,"DTSubsec");
				this.Add(0x9291,"DTOrigSS");
				this.Add(0x9292,"DTDigSS");
				this.Add(0xA000,"FPXVer");
				this.Add(0xA001,"ColorSpace");
				this.Add(0xA002,"PixXDim");
				this.Add(0xA003,"PixYDim");
				this.Add(0xA004,"RelatedWav");
				this.Add(0xA005,"Interop");
				this.Add(0xA20B,"FlashEnergy");
				this.Add(0xA20C,"SpatialFR");
				this.Add(0xA20E,"FocalXRes");
				this.Add(0xA20F,"FocalYRes");
				this.Add(0xA210,"FocalResUnit");
				this.Add(0xA214,"Subject Loc");
				this.Add(0xA215,"Exposure Index");
				this.Add(0xA217,"Sensing Method");
				this.Add(0xA300,"FileSource");
				this.Add(0xA301,"SceneType");
				this.Add(0xA302,"CfaPattern");
				this.Add(0x0,"Gps Ver");
				this.Add(0x1,"Gps LatitudeRef");
				this.Add(0x2,"Gps Latitude");
				this.Add(0x3,"Gps LongitudeRef");
				this.Add(0x4,"Gps Longitude");
				this.Add(0x5,"Gps AltitudeRef");
				this.Add(0x6,"Gps Altitude");
				this.Add(0x7,"Gps GpsTime");
				this.Add(0x8,"Gps GpsSatellites");
				this.Add(0x9,"Gps GpsStatus");
				this.Add(0xA,"Gps GpsMeasureMode");
				this.Add(0xB,"Gps GpsDop");
				this.Add(0xC,"Gps SpeedRef");
				this.Add(0xD,"Gps Speed");
				this.Add(0xE,"Gps TrackRef");
				this.Add(0xF,"Gps Track");
				this.Add(0x10,"Gps ImgDirRef");
				this.Add(0x11,"Gps ImgDir");
				this.Add(0x12,"Gps MapDatum");
				this.Add(0x13,"Gps DestLatRef");
				this.Add(0x14,"Gps DestLat");
				this.Add(0x15,"Gps DestLongRef");
				this.Add(0x16,"Gps DestLong");
				this.Add(0x17,"Gps DestBearRef");
				this.Add(0x18,"Gps DestBear");
				this.Add(0x19,"Gps DestDistRef");
				this.Add(0x1A,"Gps DestDist");
			}
		}

        //<Added by Ted Dinklocker for Pix2Gallery2 usage>
        /// <summary>
        /// Summary description for translation.
        /// </summary>
        public class IDtranslation : Hashtable
        {
            /// <summary>
            /// 
            /// </summary>
            public IDtranslation()
            {
                this.Add("Exif IFD", 0x8769);
                this.Add("Gps IFD", 0x8825);
                this.Add("New Subfile Type", 0xFE);
                this.Add("Subfile Type", 0xFF);
                this.Add("Image Width", 0x100);
                this.Add("Image Height", 0x101);
                this.Add("Bits Per Sample", 0x102);
                this.Add("Compression", 0x103);
                this.Add("Photometric Interp", 0x106);
                this.Add("Thresh Holding", 0x107);
                this.Add("Cell Width", 0x108);
                this.Add("Cell Height", 0x109);
                this.Add("Fill Order", 0x10A);
                this.Add("Document Name", 0x10D);
                this.Add("Image Description", 0x10E);
                this.Add("Equip Make", 0x10F);
                this.Add("Equip Model", 0x110);
                this.Add("Strip Offsets", 0x111);
                this.Add("Orientation", 0x112);
                this.Add("Samples PerPixel", 0x115);
                this.Add("Rows Per Strip", 0x116);
                this.Add("Strip Bytes Count", 0x117);
                this.Add("Min Sample Value", 0x118);
                this.Add("Max Sample Value", 0x119);
                this.Add("X Resolution", 0x11A);
                this.Add("Y Resolution", 0x11B);
                this.Add("Planar Config", 0x11C);
                this.Add("Page Name", 0x11D);
                this.Add("X Position", 0x11E);
                this.Add("Y Position", 0x11F);
                this.Add("Free Offset", 0x120);
                this.Add("Free Byte Counts", 0x121);
                this.Add("Gray Response Unit", 0x122);
                this.Add("Gray Response Curve", 0x123);
                this.Add("T4 Option", 0x124);
                this.Add("T6 Option", 0x125);
                this.Add("Resolution Unit", 0x128);
                this.Add("Page Number", 0x129);
                this.Add("Transfer Funcition", 0x12D);
                this.Add("Software Used", 0x131);
                this.Add("Date Time", 0x132);
                this.Add("Artist", 0x13B);
                this.Add("Host Computer", 0x13C);
                this.Add("Predictor", 0x13D);
                this.Add("White Point", 0x13E);
                this.Add("Primary Chromaticities", 0x13F);
                this.Add("ColorMap", 0x140);
                this.Add("Halftone Hints", 0x141);
                this.Add("Tile Width", 0x142);
                this.Add("Tile Length", 0x143);
                this.Add("Tile Offset", 0x144);
                this.Add("Tile ByteCounts", 0x145);
                this.Add("InkSet", 0x14C);
                this.Add("Ink Names", 0x14D);
                this.Add("Number Of Inks", 0x14E);
                this.Add("Dot Range", 0x150);
                this.Add("Target Printer", 0x151);
                this.Add("Extra Samples", 0x152);
                this.Add("Sample Format", 0x153);
                this.Add("S Min Sample Value", 0x154);
                this.Add("S Max Sample Value", 0x155);
                this.Add("Transfer Range", 0x156);
                this.Add("JPEG Proc", 0x200);
                this.Add("JPEG InterFormat", 0x201);
                this.Add("JPEG InterLength", 0x202);
                this.Add("JPEG RestartInterval", 0x203);
                this.Add("JPEG LosslessPredictors", 0x205);
                this.Add("JPEG PointTransforms", 0x206);
                this.Add("JPEG QTables", 0x207);
                this.Add("JPEG DCTables", 0x208);
                this.Add("JPEG ACTables", 0x209);
                this.Add("YCbCr Coefficients", 0x211);
                this.Add("YCbCr Subsampling", 0x212);
                this.Add("YCbCr Positioning", 0x213);
                this.Add("REF Black White", 0x214);
                this.Add("ICC Profile", 0x8773);
                this.Add("Gamma", 0x301);
                this.Add("ICC Profile Descriptor", 0x302);
                this.Add("SRGB RenderingIntent", 0x303);
                this.Add("Image Title", 0x320);
                this.Add("Copyright", 0x8298);
                this.Add("Resolution X Unit", 0x5001);
                this.Add("Resolution Y Unit", 0x5002);
                this.Add("Resolution X LengthUnit", 0x5003);
                this.Add("Resolution Y LengthUnit", 0x5004);
                this.Add("Print Flags", 0x5005);
                this.Add("Print Flags Version", 0x5006);
                this.Add("Print Flags Crop", 0x5007);
                this.Add("Print Flags Bleed Width", 0x5008);
                this.Add("Print Flags Bleed Width Scale", 0x5009);
                this.Add("Halftone LPI", 0x500A);
                this.Add("Halftone LPIUnit", 0x500B);
                this.Add("Halftone Degree", 0x500C);
                this.Add("Halftone Shape", 0x500D);
                this.Add("Halftone Misc", 0x500E);
                this.Add("Halftone Screen", 0x500F);
                this.Add("JPEG Quality", 0x5010);
                this.Add("Grid Size", 0x5011);
                this.Add("Thumbnail Format", 0x5012);
                this.Add("Thumbnail Width", 0x5013);
                this.Add("Thumbnail Height", 0x5014);
                this.Add("Thumbnail ColorDepth", 0x5015);
                this.Add("Thumbnail Planes", 0x5016);
                this.Add("Thumbnail RawBytes", 0x5017);
                this.Add("Thumbnail Size", 0x5018);
                this.Add("Thumbnail CompressedSize", 0x5019);
                this.Add("Color Transfer Function", 0x501A);
                this.Add("Thumbnail Data", 0x501B);
                this.Add("Thumbnail ImageWidth", 0x5020);
                this.Add("Thumbnail ImageHeight", 0x502);
                this.Add("Thumbnail BitsPerSample", 0x5022);
                this.Add("Thumbnail Compression", 0x5023);
                this.Add("Thumbnail PhotometricInterp", 0x5024);
                this.Add("Thumbnail ImageDescription", 0x5025);
                this.Add("Thumbnail EquipMake", 0x5026);
                this.Add("Thumbnail EquipModel", 0x5027);
                this.Add("Thumbnail StripOffsets", 0x5028);
                this.Add("Thumbnail Orientation", 0x5029);
                this.Add("Thumbnail SamplesPerPixel", 0x502A);
                this.Add("Thumbnail RowsPerStrip", 0x502B);
                this.Add("Thumbnail StripBytesCount", 0x502C);
                this.Add("Thumbnail ResolutionX", 0x502D);
                this.Add("Thumbnail ResolutionY", 0x502E);
                this.Add("Thumbnail PlanarConfig", 0x502F);
                this.Add("Thumbnail ResolutionUnit", 0x5030);
                this.Add("Thumbnail TransferFunction", 0x5031);
                this.Add("Thumbnail SoftwareUsed", 0x5032);
                this.Add("Thumbnail DateTime", 0x5033);
                this.Add("Thumbnail Artist", 0x5034);
                this.Add("Thumbnail WhitePoint", 0x5035);
                this.Add("Thumbnail PrimaryChromaticities", 0x5036);
                this.Add("Thumbnail YCbCrCoefficients", 0x5037);
                this.Add("Thumbnail YCbCrSubsampling", 0x5038);
                this.Add("Thumbnail YCbCrPositioning", 0x5039);
                this.Add("Thumbnail RefBlackWhite", 0x503A);
                this.Add("Thumbnail CopyRight", 0x503B);
                this.Add("Luminance Table", 0x5090);
                this.Add("Chrominance Table", 0x5091);
                this.Add("Frame Delay", 0x5100);
                this.Add("Loop Count", 0x5101);
                this.Add("Pixel Unit", 0x5110);
                this.Add("Pixel PerUnit X", 0x5111);
                this.Add("Pixel PerUnit Y", 0x5112);
                this.Add("Palette Histogram", 0x5113);
                this.Add("Exposure Time", 0x829A);
                this.Add("F-Number", 0x829D);
                this.Add("Exposure Prog", 0x8822);
                this.Add("Spectral Sense", 0x8824);
                this.Add("ISO Speed", 0x8827);
                this.Add("OECF", 0x8828);
                this.Add("Ver", 0x9000);
                this.Add("DTOrig", 0x9003);
                this.Add("DTDigitized", 0x9004);
                this.Add("CompConfig", 0x9101);
                this.Add("CompBPP", 0x9102);
                this.Add("Shutter Speed", 0x9201);
                this.Add("Aperture", 0x9202);
                this.Add("Brightness", 0x9203);
                this.Add("Exposure Bias", 0x9204);
                this.Add("MaxAperture", 0x9205);
                this.Add("SubjectDist", 0x9206);
                this.Add("Metering Mode", 0x9207);
                this.Add("LightSource", 0x9208);
                this.Add("Flash", 0x9209);
                this.Add("FocalLength", 0x920A);
                this.Add("Maker Note", 0x927C);
                this.Add("User Comment", 0x9286);
                this.Add("DTSubsec", 0x9290);
                this.Add("DTOrigSS", 0x9291);
                this.Add("DTDigSS", 0x9292);
                this.Add("FPXVer", 0xA000);
                this.Add("ColorSpace", 0xA001);
                this.Add("PixXDim", 0xA002);
                this.Add("PixYDim", 0xA003);
                this.Add("RelatedWav", 0xA004);
                this.Add("Interop", 0xA005);
                this.Add("FlashEnergy", 0xA20B);
                this.Add("SpatialFR", 0xA20C);
                this.Add("FocalXRes", 0xA20E);
                this.Add("FocalYRes", 0xA20F);
                this.Add("FocalResUnit", 0xA210);
                this.Add("Subject Loc", 0xA214);
                this.Add("Exposure Index", 0xA215);
                this.Add("Sensing Method", 0xA217);
                this.Add("FileSource", 0xA300);
                this.Add("SceneType", 0xA301);
                this.Add("CfaPattern", 0xA302);
                this.Add("Gps Ver", 0x0);
                this.Add("Gps LatitudeRef", 0x1);
                this.Add("Gps Latitude", 0x2);
                this.Add("Gps LongitudeRef", 0x3);
                this.Add("Gps Longitude", 0x4);
                this.Add("Gps AltitudeRef", 0x5);
                this.Add("Gps Altitude", 0x6);
                this.Add("Gps GpsTime", 0x7);
                this.Add("Gps GpsSatellites", 0x8);
                this.Add("Gps GpsStatus", 0x9);
                this.Add("Gps GpsMeasureMode", 0xA);
                this.Add("Gps GpsDop", 0xB);
                this.Add("Gps SpeedRef", 0xC);
                this.Add("Gps Speed", 0xD);
                this.Add("Gps TrackRef", 0xE);
                this.Add("Gps Track", 0xF);
                this.Add("Gps ImgDirRef", 0x10);
                this.Add("Gps ImgDir", 0x11);
                this.Add("Gps MapDatum", 0x12);
                this.Add("Gps DestLatRef", 0x13);
                this.Add("Gps DestLat", 0x14);
                this.Add("Gps DestLongRef", 0x15);
                this.Add("Gps DestLong", 0x16);
                this.Add("Gps DestBearRef", 0x17);
                this.Add("Gps DestBear", 0x18);
                this.Add("Gps DestDistRef", 0x19);
                this.Add("Gps DestDist", 0x1A); 
            }
        }
        //</Added by Ted Dinklocker for Pix2Gallery2 usage>
                
        /// <summary>
		/// private class
		/// </summary>
		internal class Rational
		{
			private int n;
			private int d;
			public Rational(int n, int d)
			{
				this.n = n;
				this.d = d;
				simplify(ref this.n, ref this.d);
			}
			public Rational(uint n, uint d)
			{
				this.n = Convert.ToInt32(n);
				this.d = Convert.ToInt32(d);

				simplify(ref this.n, ref this.d);
			}
			public Rational()
			{
				this.n= this.d=0;
			}
			public string ToString(string sp)
			{
				if( sp == null ) sp = "/";
				return n.ToString() + sp + d.ToString();
			}
			public double ToDouble()
			{
				if( d == 0 )
					return 0.0;

				return Math.Round(Convert.ToDouble(n)/Convert.ToDouble(d),2);
			}
			private void simplify( ref int a, ref int b )
			{
				if( a== 0 || b == 0 )
					return;

				int	gcd = euclid(a,b);
				a /= gcd;
				b /= gcd;
			}
			private int euclid(int a, int b)
			{
				if(b==0)	
					return a;
				else		
					return euclid(b,a%b);
			}
		}
	}
}